import { getUserTabs, getAllChannels } from '@/api/channels'
export default {
  state: {
    activeChannel: null,
    allChannels: [],
    userChannels: []
  },
  mutations: {
    // 赋值 当前激活频道id
    changeActiveChannel(state, active) {
      state.activeChannel = active
    },
    // 赋值 所有频道
    getAllChannels(state, tabs) {
      state.allChannels = tabs
    },
    // 赋值 用户频道
    getUserChannels(state, tabs) {
      state.userChannels = tabs
    }
  },
  actions: {
    // 获取 用户频道 - 请求
    async getTabs(context) {
      const res = await getUserTabs()
      context.commit('getUserChannels', res.data.channels)
    },
    // 获取 所有频道 - 请求
    async getAllTabs(context) {
      const res = await getAllChannels()
      context.commit('getAllChannels', res.data.channels)
    }
  },
  getters: {
    //   可选频道
    checkChannels: (state) => {
      return state.allChannels.filter(val => !state.userChannels.some(item => item.id === val.id))
    }
  },
  namespaced: true
}
